package com.feng.controller;

import com.feng.domain.ResponseResult;
import com.feng.domain.dto.ChangeRoleStatusDto;
import com.feng.domain.dto.RoleSaveDto;
import com.feng.domain.dto.RoleUpdateDto;
import com.feng.domain.entity.Role;
import com.feng.domain.entity.User;
import com.feng.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/role")
public class RoleController {
     @Autowired
    private RoleService roleService;
    @GetMapping("/list")
    public ResponseResult list(Role role, Integer pageNum, Integer pageSize) {
        return roleService.selectRolePage(role,pageNum,pageSize);
    }
    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody ChangeRoleStatusDto roleStatusDto){
        Role role = new Role();
        role.setId(roleStatusDto.getRoleId());
        role.setStatus(roleStatusDto.getStatus());
        roleService.updateById(role);
        return ResponseResult.okResult();
    }
    @PostMapping
    public  ResponseResult saveRole(@RequestBody RoleSaveDto roleSavevo){
        return roleService.saveRole(roleSavevo);
    }
    @GetMapping("/{roleId}")
    public ResponseResult getRoleById(@PathVariable Long roleId){
       return roleService.getRoleById(roleId);
    }
    @PutMapping
    public ResponseResult updateByDetails(@RequestBody RoleUpdateDto roleUpdateDto){
        return roleService.updateByDetails(roleUpdateDto);
    }
    @DeleteMapping("/{id}")
    public ResponseResult remove(@PathVariable List<Long> id) {
        for (Long aLong : id) {
            roleService.removeById(aLong);
        }

        return ResponseResult.okResult();
    }
    @GetMapping("/listAllRole")
    public ResponseResult listRole(){
       return roleService.listRole();
    }

}
